import * as React from "react";
import ChatList from "./routes/ChatList";
import ChatDetail from "./routes/ChatDetail";
import ChatPage from "./routes/ChatPage";

export interface MenuItem {
  key: string;
  name?: string;
  icon?: any;
  /** 跳转配置 */
  href?: string;
  /** 路由配置 */
  path?: string;
  children?: MenuItem[];
  component?: React.ComponentType;
  hide?: boolean;
  exact?: boolean;
  fullscreen?: boolean;
  closable?: boolean;
  no_back?: boolean;
}

/** 支持两级菜单 */
export const getMenus = (): MenuItem[] => {
  const menus: MenuItem[] = [
    {
      key: "/",
      path: "/",
      name: "群聊",
      component: ChatList,
    },
    {
      key: "/chat_detail/:id",
      path: "/chat_detail/:id",
      name: "群聊信息",
      component: ChatDetail,
    },
    {
      key: "/chat_page/:id",
      path: "/chat_page/:id",
      name: "会话页",
      component: ChatPage,
    },
    // {
    //   key: "/",
    //   path: "/",
    //   name: "xxx",
    //   component: ChatHome,
    // },
  ];
  return menus.filter((m) => m);
};

/** 支持两级菜单 */
export const getRoutes = () => {
  const menus = getMenus();
  const routes: MenuItem[] = [];
  menus.map(({ children, ...menu }) => {
    if (menu.path) {
      routes.push(menu);
    }
    if (children && children.length) {
      children.map((c) => {
        if (c.path) {
          routes.push(c);
        }
      });
    }
  });
  return routes;
};

export const getHome = () => getRoutes()[0];
